package com.hondee.fuzzyquery.entity.access.querycondition;

import java.util.ArrayList;
import java.util.List;

import com.hondee.fuzzyquery.entity.access.IQueryCondition;

public class FuzzyConditionGenerator {

	public static IQueryCondition generate(String[] fuzzyField,String[] fuzzyValue){
		if(fuzzyField==null || fuzzyField.length==0){
			return null;
		}
		if(fuzzyValue==null || fuzzyValue.length==0){
			return null;
		}
		
		List<IQueryCondition> rootList = new ArrayList<>();
		for(String value : fuzzyValue){
			List<IQueryCondition> subList = new ArrayList<>();
			for(String field : fuzzyField){
				subList.add(new SqlQueryCondition(Logic.NONE, SqlWhereConditionEnum.CONTAIN, field, value));
			}
			rootList.add(new SqlQueryCondition(Logic.OR, subList));
		}
		
		return new SqlQueryCondition(Logic.AND, rootList);
	}
}
